<template>
  <div class="f-menu" :style="{ width: $store.state.asideWidth }">
    <el-menu
      :default-active="defaultActive"
      unique-opened
      :collapse="isCollapse"
      default-active="2"
      class="border-0"
      @select="handleSelect"
      :collapse-transition="false"
    >
      <template
        v-for="(item, index) in asideMenus.filter(
          (item) => item.role <= $store.state.user.role
        )"
        :key="index"
      >
        <el-sub-menu
          v-if="item.child && item.child.length > 0"
          :index="item.name"
        >
          <template #title>
            <el-icon>
              <component :is="item.icon"></component>
            </el-icon>
            <span>{{ item.name }}</span>
          </template>

          <el-menu-item
            v-for="(item2, index2) in item.child"
            :key="index2"
            :index="item2.frontpath"
          >
            <el-icon>
              <component :is="item2.icon"></component>
            </el-icon>
            <span>{{ item2.name }}</span>
          </el-menu-item>
        </el-sub-menu>

        <el-menu-item v-else :index="item.frontpath">
          <el-icon><component :is="item.icon"></component></el-icon>
          <span>{{ item.name }}</span>
        </el-menu-item>
      </template>
    </el-menu>
  </div>
</template>

<script setup>
import { useRouter, useRoute } from "vue-router";
import { computed, ref } from "vue";
import { useStore } from "vuex";

const router = useRouter();
const store = useStore();
const route = useRoute();

const defaultActive = ref(route.path);

// 是否折叠
const isCollapse = computed(() => !(store.state.asideWidth == "250px"));

// const asideMenus = computed(()=>store.state.menus)
const asideMenus = [
  {
    name: "项目申报",
    icon: "Document",
    role: 1,
    child: [
      {
        name: "新建项目",
        icon: "DocumentAdd",
        frontpath: "/project/create_project",
      },
      {
        name: "已提交项目",
        icon: "FolderChecked",
        frontpath: "/project/list",
      },
      // {
      //   name: "草稿",
      //   icon: "Memo",
      //   frontpath: "/project/project_draft",
      // },
    ],
  },
  {
    name: "项目审核",
    icon: "Files",
    role: 2,
    child: [
      {
        name: "批次管理",
        icon: "Notebook",
        frontpath: "/project_audit/batch_manager",
      },
      {
        name: "待打标签项目",
        icon: "FolderOpened",
        frontpath: "/project_audit/get_tagging_project",
      },
      {
        name: "待评分项目",
        icon: "Folder",
        frontpath: "/project_audit/get_pending_project",
      },
      {
        name: "已评分项目",
        icon: "FolderChecked",
        frontpath: "/project_audit/get_audited_project",
      },
      {
        name: "批次项目列表",
        icon: "List",
        frontpath: "/project_audit/result_audit",
      },
    ],
  },
  {
    name: "系统管理",
    icon: "shopping-bag",
    role: 4,
    child: [
      {
        name: "评审组成员管理",
        icon: "shopping-cart-full",
        frontpath: "/role/list",
      },
      {
        name: "评审规则管理",
        icon: "shopping-cart-full",
        frontpath: "/role/list",
      },
      {
        name: "数据统计",
        icon: "Histogram",
        frontpath: "/getStatisticsInfo",
      },
    ],
  },
];

const handleSelect = (e) => {
  router.push(e);
};
</script>

<style>
.f-menu {
  transition: all 0.2s;
  top: 64px;
  bottom: 0;
  left: 0;
  overflow-y: auto;
  overflow-x: hidden;
  @apply shadow fixed bg-light-100;
}

/* 隐藏滚动条 */
.f-menu::-webkit-scrollbar {
  width: 0px;
}
</style>
